<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>编辑商品分类页面</title>
<link rel="stylesheet" href="layui/css/layui.css" />
</head>
<body>
	<form class="layui-form"  style="margin-top: 20px;">
		<div class="layui-form-item" hidden="hidden">
			<label class="layui-form-label">ID：</label>
			<div class="layui-input-inline">
				<input type="text" name="pcat_id" id="pcat_id" required
					lay-verify="required" class="layui-input" >
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">分类名称：</label>
			<div class="layui-input-inline">
				<input type="text" name="pcat_name" id="pcat_name" required
					lay-verify="required" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">上级分类：</label>
			<div class="layui-input-inline">
				<input type="text" name="p_parcate" id="p_parcate" required
					lay-verify="required" class="layui-input">
			</div>
		</div>
		
		<div class="layui-form-item">
			<label class="layui-form-label">子级图标：</label>
			<div class="layui-input-inline">
			 <button type="button" class="layui-btn layui-btn layui-btn-sm" id="test1">
					<i class="layui-icon">&#xe64a;</i>上传图标
				</button>
				<img id="imgFace"  style="width:120px" src=""/>
				<input type="text" name="p_icon" id="p_icon" required
					lay-verify="required" class="layui-input">
			</div>
		</div>
		
		<div class="layui-btn-container" style="text-align: center;">
			<button class="layui-btn" lay-submit="" lay-filter="userEdit">修改</button>
		</div>
	</form>
	<script type="text/javascript" src="layui/layui.js"></script>
	<script>
	layui.use([ 'form', 'upload' ], function() {
		var form = layui.form;
		var $ = layui.jquery;
		var upload = layui.upload;
		//执行实例
		  var uploadInst = upload.render({
		    elem: '#test1' //绑定元素
		    ,url: '/wk1un2_electricity_digital/UploadpictServlet?method=upload' //上传接口
		    ,acceptMine:'img/*'
		    ,done: function(res){
		      //上传完毕回调
		      console.log(res.code);
		      $("#p_icon").val('upload/' + res.data);
		      $("#imgFace").css('display', 'block');
		      $("#imgFace").attr("src", "/wk1un2_electricity_digital/Backstage/upload/" + res.data);
		  layer.smg('新图片更新成功',{
			  icon:6,
			  time:1500
		  },function(){});
	 },
	 error: function(){
		      //请求异常回调
		 
		    }
		  });
			//监听提交
			form.on('submit(userEdit)', function(data) {
				var d = data.field;
				d.method = "update";
				console.log(d);
				var url = '/wk1un2_electricity_digital/Backstage/updateProductCategory';
				$.post(url, d, function(data) {
					if (data.count > 0) {
						console.log('修改成功');
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
					}
				}, "json");
				return false;
			});
		});
	</script>
</body>
</html>